const User = require('../../db/userSchema');
module.exports = async(req, res) => {
    // 得到请求数据
    // console.log(req.query.username);

    // 1.当前页
    // 2.每页几条数据
    // 3.一共多少页
    // 4.返回当前页的数据
    let page = Number(req.query.page) || 1;
    let size = req.query.size || 5;

    // 一共多少条数据
    let total = await User.countDocuments({ "username": new RegExp(req.query.username, 'gi') });
    // 一共多少页
    let totalPage = Math.ceil(total / size);
    // 当前页
    // 跳过去多少p条数据

    let skipdata = (page - 1) * size;
    // 共查询的数据
    let relData = await User.find({ "username": new RegExp(req.query.username, 'gi') }).limit(size).skip(skipdata);

    res.render('./admin/searchuser.ejs', {
        userlist: relData,
        total: total,
        totalPage: totalPage,
        page: page,
        searchname: req.query.username
    });










    let searchRel = await User.find({ "username": req.query.username });



}